namespace Haushaltsbuch.DataAcces.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class FirstMigration : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Users",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Username = c.String(maxLength: 255),
                        Passwort = c.Binary(),
                        Firstname = c.String(),
                        Lastname = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Roles",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(maxLength: 255),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Shops",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Strasse = c.String(),
                        Ort = c.String(),
                        Plz = c.String(),
                        Geaendert = c.DateTime(nullable: false),
                        Erstellt = c.DateTime(nullable: false),
                        GeaendertVon_Id = c.Int(),
                        ErstelltVon_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Users", t => t.GeaendertVon_Id)
                .ForeignKey("dbo.Users", t => t.ErstelltVon_Id)
                .Index(t => t.GeaendertVon_Id)
                .Index(t => t.ErstelltVon_Id);
            
            CreateTable(
                "dbo.UserRoles",
                c => new
                    {
                        User_Id = c.Int(nullable: false),
                        Role_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.User_Id, t.Role_Id })
                .ForeignKey("dbo.Users", t => t.User_Id, cascadeDelete: true)
                .ForeignKey("dbo.Roles", t => t.Role_Id, cascadeDelete: true)
                .Index(t => t.User_Id)
                .Index(t => t.Role_Id);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.UserRoles", new[] { "Role_Id" });
            DropIndex("dbo.UserRoles", new[] { "User_Id" });
            DropIndex("dbo.Shops", new[] { "ErstelltVon_Id" });
            DropIndex("dbo.Shops", new[] { "GeaendertVon_Id" });
            DropForeignKey("dbo.UserRoles", "Role_Id", "dbo.Roles");
            DropForeignKey("dbo.UserRoles", "User_Id", "dbo.Users");
            DropForeignKey("dbo.Shops", "ErstelltVon_Id", "dbo.Users");
            DropForeignKey("dbo.Shops", "GeaendertVon_Id", "dbo.Users");
            DropTable("dbo.UserRoles");
            DropTable("dbo.Shops");
            DropTable("dbo.Roles");
            DropTable("dbo.Users");
        }
    }
}
